//
//  YZFeedbackVC.m
//  VET
//
//  Created by 刘文靖 on 2018/6/29.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZFeedbackVC.h"
#import "UITextView+YZPlaceholder.h"
#import "YZGradientBtn.h"
#import "YZPersonalVM.h"
#import "ZYKeyboardUtil.h"
@interface YZFeedbackVC ()
@property (weak, nonatomic) IBOutlet UITextView *feedbackTF;
@property (weak, nonatomic) IBOutlet YZGradientBtn *submitButton;
@property (strong, nonatomic) YZPersonalVM *viewModel;
@property (strong, nonatomic) ZYKeyboardUtil *keyboardUtil;
@property (weak, nonatomic) IBOutlet UIButton *functionalBtn;
@property (weak, nonatomic) IBOutlet UIButton *productBtn;
@property (weak, nonatomic) IBOutlet UIButton *otherBtn;
@end
@implementation YZFeedbackVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"反馈";
    self.submitButton.enabled = NO;
    [self.feedbackTF addPlaceholderWithText:@"请补充相信问题和意见" textColor:kColorWithHex(0xCECECE) font:[UIFont fontWithName:@"PingFangSC-Regular" size:14]];
    [self configKeyBoardRespond];
}
- (IBAction)submitButtonClicked {
    NSString *feedbackType = [NSString stringWithFormat:@"%d%d%d",self.functionalBtn.selected,self.productBtn.selected,self.otherBtn.selected];
    [[self.viewModel submitFeedback:feedbackType content:self.feedbackTF.text] subscribeNext:^(id  _Nullable x) {
        ;
    } completed:^{
        [SVProgressHUD yz_showMessage:@"提交成功"];
        [self.navigationController popViewControllerAnimated:YES];
        
    }];
}

- (YZPersonalVM *)viewModel{
    if (!_viewModel) {
        _viewModel = [[YZPersonalVM alloc] init];
    }
    return _viewModel;
}


- (void)configKeyBoardRespond {
    self.keyboardUtil = [[ZYKeyboardUtil alloc] initWithKeyboardTopMargin:MARGIN_KEYBOARD];
    @weakify(self)
    [_keyboardUtil setAnimateWhenKeyboardAppearAutomaticAnimBlock:^(ZYKeyboardUtil *keyboardUtil) {
        @strongify(self)
        [keyboardUtil adaptiveViewHandleWithController:self adaptiveView:self.feedbackTF, nil];
    }];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    [self.view endEditing:YES];
}
- (IBAction)functionBtnClicked {
    self.functionalBtn.selected = !self.functionalBtn.selected;
    self.submitButton.enabled = self.functionalBtn.selected || self.productBtn.selected || self.otherBtn.selected;
}
- (IBAction)productBtnClicked {
    self.productBtn.selected = !self.productBtn.selected;
    self.submitButton.enabled = self.functionalBtn.selected || self.productBtn.selected || self.otherBtn.selected;
}
- (IBAction)otherBtnClicked {
    self.otherBtn.selected = !self.otherBtn.selected;
    self.submitButton.enabled = self.functionalBtn.selected || self.productBtn.selected || self.otherBtn.selected;
}


@end
